package community.hospital.service.domain.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import community.hospital.entity.OperationLog;
import community.hospital.entity.request.OperationLogRequest;
import community.hospital.service.domain.OperationLogService;
import community.hospital.mapper.OperationLogMapper;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author ydj
* @description 针对表【operation_log】的数据库操作Service实现
* @createDate 2023-02-04 18:41:59
*/
@Service
public class OperationLogServiceImpl extends ServiceImpl<OperationLogMapper, OperationLog>
    implements OperationLogService{

    @Override
    public Page<OperationLog> listOperationLog(OperationLogRequest request) {
        Long userId = request.getUserId();
        String moduleName = request.getModuleName();
        String methodName = request.getMethodName();
        Date startTime = request.getStartTime();
        Date endTime = request.getEndTime();
        Page<OperationLog> page = new Page<>(request.getPageNumber(), request.getPageSize());
        lambdaQuery().eq(userId != null, OperationLog::getUserId, userId)
                .eq(StrUtil.isNotBlank(moduleName), OperationLog::getModuleName, moduleName)
                .eq(StrUtil.isNotBlank(methodName), OperationLog::getMethodName, methodName)
                .ge(startTime != null, OperationLog::getGmtCreate, startTime)
                .eq(endTime != null, OperationLog::getGmtCreate, endTime)
                .orderByDesc(OperationLog::getGmtCreate)
                .page(page);
        return page;
    }

}




